/**
 * 
 */
package cl.webservice;

import org.apache.http.HttpConnection;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;

/**
 * @author MariaJose
 *
 */
public class WebserviceUpdateSms {
	private static String METHOD_NAME ;
	private static String NAMESPACE ;
	private static String URL;

	/**
	 * Datos del ws de mi localhost
	 */
	public void coneccionwsPropio(){

		METHOD_NAME = "cambioEstado";
		NAMESPACE = "http://ws.cl/";
		URL = "http://186.10.141.140:8080/AndroidSmsws/services/ActualizacionWs";

	}
	/**
	 * datos del ws alojado en el servidor londres
	 */
	public void coneccionwsServidorLon(String url){
		METHOD_NAME = "cambioEstado";
		NAMESPACE = "http://ws.cl/";
//		URL = "http://200.13.4.205:8080/AndroidSmsws1/services/ActualizacionWs?wsdl";
//		String urlpagina = "200.13.4.205";
		if(!url.equals("")){
			URL = "http://"+url+":8080/AndroidSmsws1/services/ActualizacionWs?wsdl";
		}
		else{
			URL = "http://200.13.4.205:8080/AndroidSmsws1/services/ActualizacionWs?wsdl";
		}

		
	}
	/**
	 * datos del ws alojado en el servidor ceis
	 */
	public void coneccionwsServidorCei(){

		METHOD_NAME = "cambioEstado";
		NAMESPACE = "http://ws.cl/";
		URL = "http://50.19.101.44:8080/AndroidSms/services/ActualizacionWs?wsdl";
	}
	/**
	 * 
	 * @param methodName
	 */

	public String updateSms(String json,String url){


		coneccionwsServidorLon(url);

		String SOAP_ACTION = NAMESPACE + METHOD_NAME;

		SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
		PropertyInfo updatesms = new PropertyInfo();
		updatesms.setName("jsonsms");
		updatesms.setValue(json);
		updatesms.setType(String.class);

		request.addProperty(updatesms);
		//		request.addAttribute("jsonsms", json);

		SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		soapEnvelope.dotNet = true;
		soapEnvelope.implicitTypes =true;
		soapEnvelope.setOutputSoapObject(request);




		AndroidHttpTransport aht = new AndroidHttpTransport(URL);
	
		String returnUpdate;
		try
		{
			aht.call(SOAP_ACTION, soapEnvelope);
			SoapPrimitive resultString = (SoapPrimitive)soapEnvelope.getResponse();
			returnUpdate =resultString.toString();
			return returnUpdate;
		}
		catch (Exception e)
		{
			e.printStackTrace();
			returnUpdate = "Error Conexion";}
		return returnUpdate;


	}
}
